<?php

# mvblogs_2-0
# 2006 Oct 06  09:15:53
# Users model class

class UsersModel
{
    private function __construct() {}
    private static function query($query)
    {
        $conn = getDBConnection();
        $result = $conn->query($query);
        if (mysqli_errno($conn)) {
            throw new Exception(mysqli_error($conn));
        }
        $user = $result->fetch_assoc();
        unset($user['password']);
        return $user;
    }

    public static function getByUserId($userId)
    {
        return UsersModel::query(
            "SELECT *, MD5(CONCAT(`email`, `password`)) AS `hash` FROM users "
          . "WHERE `user_id`='{$userId}'");
    }

    public static function getByEmail($email)
    {
        return UsersModel::query(
            "SELECT *, MD5(CONCAT(`email`, `password`)) AS `hash` FROM users "
          . "WHERE email = '{$email}'");
    }

    public static function getByHash($hash)
    {
        return UsersModel::query(
            "SELECT *, MD5(CONCAT(`email`, `password`)) AS `hash` FROM users "
          . "WHERE MD5(CONCAT(`email`, `password`))='{$hash}'");
    }
}